#include<iostream>
#include<cstring> 
using namespace std;
const int N = 110;
int dis[N];
int lever[N];
int g[N][N];
int n, m;
bool st[N];
int dij(int down, int up)
{
	memset(dis, 0x3f, sizeof(dis));
	dis[0] = 0;
	memset(st, 0, sizeof(st));
	for (int i = 0; i <= n; i++) {
		int t = -1;
		for (int j = 0; j <= n; j++) {
			if (!st[j] && (dis[t] > dis[j] || t == -1)) {
				t = j;
			}
		}
		st[t] = 1;
		//cout<<"t=="<<t<<endl;
		for (int j = 1; j <= n; j++) {
			if (lever[j] >= down && lever[j] <= up) {
				dis[j] = min(dis[j], dis[t] + g[t][j]);
				//cout<<"dis[j]=="<<j<<" "<<dis[j]<<endl;
			}
		}
	}
	//cout<<"dis1===="<<dis[1]<<endl;
	return dis[1];
}
int main()
{
	cin >> m >> n;
	memset(g, 0x3f, sizeof(g));
	for (int i = 1; i <= n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		g[0][i] = a;
		lever[i] = b;
		while (c--) {
			int x, y;
			cin >> x >> y;
			g[x][i] = y;
		}
	}
	int ans = 1e9;
	for (int i = lever[1] - m; i <= lever[1]; i++) {
		ans = min(ans, dij(i, i + m));
	}
	cout << ans << endl;
	return 0;
}